<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/9
 * Time: 11:57
 */
header("Content-type:JSON;charset=utf-8");  //统一输出编码为utf-8
header("Access-Control-Allow-Origin:*");//允许跨域

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $username = $_POST["userName"];
    $userpwd = $_POST["userPwd"];
    $conn = new mysqli("127.0.0.1", "root", "", "zhiwoyaowang");
    mysqli_query($conn, "set names utf8");
//    $sql = "SELECT*FROM userinfo WHERE u_tel='" . $username . "' AND u_pwd='" . $userpwd . "'";
//    $result = $conn->query($sql);
    $sql = "SELECT*FROM userinfo WHERE u_tel=? AND u_pwd=?";
    $stmt = $conn->prepare($sql);//预查询
    $stmt->bind_param("ss",$username,$userpwd);
    $stmt->execute();
    $result = $stmt->get_result();
    $resultArr = Array();
    if ($result->num_rows >= 1) {
        $resultArr["status"] = 1;
        $resultArr["msg"] = "登录成功";
        $resultArr["tel"] = $username;
        session_start();
        $_SESSION["USER"] = $username;
        //只登陆成功后，才能创建session
    } else {
        $resultArr["status"] = 0;
        $resultArr["msg"] = "登录失败";

    }
    print_r(json_encode($resultArr));
}